//
//  CreditCardBillHeadView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/24.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class CreditCardBillHeadView: UIView {
    
    fileprivate let whiteView = UIView()
    fileprivate let bankLabel = UILabel() //银行名称
    fileprivate let billAmountLabel = UILabel() //账单金额
    fileprivate let dueTimeLabel = UILabel() //账单逾期
    fileprivate let amountLabel = UILabel() //金额
    
    fileprivate var repaymentView : RepaymentDateView! //还款日
    fileprivate var billDetailsView : BillDetailsView! //账单详情
    fileprivate var billLinesView : BillLinesView! //账单额度

    init(model:InputBillModel) {
        super.init(frame: .zero)
        
        self.backgroundColor = UIColor.mineColor()
        
        whiteView.backgroundColor = UIColor.white
        self.addSubview(whiteView)
        
        bankLabel.text = model.bank! + creditCard + "  " + lastNumber + "  " + model.number!
        bankLabel.textColor = UIColor.gray
        bankLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 18))
        whiteView.addSubview(bankLabel)
        
        billAmountLabel.text = billAmount
        billAmountLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 18))
        whiteView.addSubview(billAmountLabel)
        
        dueTimeLabel.textAlignment = .center
        dueTimeLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 12))
        whiteView.addSubview(dueTimeLabel)
        
        amountLabel.textColor = UIColor.red
        amountLabel.font = UIFont.boldSystemFont(ofSize: RATIO(maxNum: 20))
        whiteView.addSubview(amountLabel)
        
        if model.isPay == "1" {
            amountLabel.text = "0"
            dueTimeLabel.text = repaymenting
            dueTimeLabel.textColor = UIColor.white
            dueTimeLabel.backgroundColor = UIColor.green
        }else{
            amountLabel.text = model.billLines
            dueTimeLabel.text = model.repaymentDate?.distanceRepaymentDate()
            dueTimeLabel.textColor = UIColor.white
            dueTimeLabel.backgroundColor = UIColor.red
        }
        
        repaymentView = RepaymentDateView.init(model: model)
        self.addSubview(repaymentView)
        
        billDetailsView = BillDetailsView.init(model: model)
        self.addSubview(billDetailsView)
        
        billLinesView = BillLinesView.init(model: model)
        self.addSubview(billLinesView)
        
        whiteView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 140))
        }
        
        bankLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 10))
            make.centerX.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        billAmountLabel.snp.makeConstraints { (make) in
            make.top.equalTo(bankLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.centerX.equalTo(bankLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        dueTimeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(billAmountLabel.snp.right).offset(RATIO(maxNum: 10))
            make.centerY.equalTo(billAmountLabel)
            make.width.equalTo((model.repaymentDate?.distanceRepaymentDate().size(font: RATIO(maxNum: 12), height: RATIO_H(maxNum: 15)).width)!)
            make.height.equalTo(RATIO_H(maxNum: 15))
        }
        
        amountLabel.snp.makeConstraints { (make) in
        make.top.equalTo(billAmountLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.centerX.equalTo(billAmountLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        repaymentView.snp.makeConstraints { (make) in
            make.top.equalTo(whiteView.snp.bottom).offset(1)
            make.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 40))
        }
        
        billDetailsView.snp.makeConstraints { (make) in
            make.top.equalTo(repaymentView.snp.bottom).offset(1)
            make.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 40))
        }
        
        billLinesView.snp.makeConstraints { (make) in
            make.top.equalTo(billDetailsView.snp.bottom).offset(1)
            make.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 80))
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
